package svc

import (
	"api/internal/config"
	"api/internal/middleware"
	"github.com/zeromicro/go-zero/rest"
	"github.com/zeromicro/go-zero/zrpc"
	"goods-srv/goods"
	"goods-srv/goodsclient"
	"order-srv/order"
	"order-srv/orderclient"
	"shoppingcart-srv/shoppingcart"
	"shoppingcart-srv/shoppingcartclient"
	"user-srv/user"
	"user-srv/userclient"
)

type ServiceContext struct {
	Config          config.Config
	AuthToken       rest.Middleware
	UserSrv         user.UserClient
	GoodsSrv        goods.GoodsClient
	ShoppingCartSrv shoppingcart.ShoppingcartClient
	OrderSrv        order.OrderClient
}

func NewServiceContext(c config.Config) *ServiceContext {
	return &ServiceContext{
		Config:          c,
		AuthToken:       middleware.NewAuthTokenMiddleware().Handle,
		UserSrv:         userclient.NewUser(zrpc.MustNewClient(c.UserSrv)),
		GoodsSrv:        goodsclient.NewGoods(zrpc.MustNewClient(c.GoodsSrv)),
		ShoppingCartSrv: shoppingcartclient.NewShoppingcart(zrpc.MustNewClient(c.ShoppingCartSrv)),
		OrderSrv:        orderclient.NewOrder(zrpc.MustNewClient(c.OrderSrv)),
	}
}
